using System.Data;
using System.Data.SqlClient;
using VanTaiProperty;
namespace VanTaiData
{
    public class clsTMMemberController
    {
        private clsConnect cls = new clsConnect();
        private DataTable dt;
        #region[Get-Data]
        public DataTable BindGirdTMMember()
        {
            return cls.BindGridData("sp_TMMember");
        }
        public DataTable BindGirdTMMember_Detail_Edit(int id)
        {
            return cls.LayDuLieuParameter("sp_TMMember_Detail_Edit", "@Member_ID", id);
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertTMMember(clsTMMemberProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Member_Alias", data.Member_Alias);
            cls.AddParameter("@FullNameMem", data.FullNameMem);
            cls.AddParameter("@FullName_E", data.FullName_E);
            cls.AddParameter("@FullName_C", data.FullName_C);
            cls.AddParameter("@Alias_Mem", data.Alias_Mem);
            cls.AddParameter("@Brith_Mem", data.Brith_Mem);
            cls.AddParameter("@Sex_Mem", data.Sex_Mem);
            cls.AddParameter("@Address_Mem", data.Address_Mem);
            cls.AddParameter("@Household_Mem", data.Household_Mem);
            cls.AddParameter("@PlaceOFBirth_Mem", data.PlaceOFBirth_Mem);
            cls.AddParameter("@Origin_Mem", data.Origin_Mem);
            cls.AddParameter("@ID_Religion_Mem", data.ID_Religion_Mem);
            cls.AddParameter("@ID_Ethnicity_Mem", data.ID_Ethnicity_Mem);
            cls.AddParameter("@PhoneNumber_Mem", data.PhoneNumber_Mem);
            cls.AddParameter("@Email_Mem", data.Email_Mem);
            cls.AddParameter("@Number_CMT_Mem", data.Number_CMT_Mem);
            cls.AddParameter("@Number_Car_Mem", data.Number_Car_Mem);
            cls.AddParameter("@Note_Mem", data.Note_Mem);
            cls.AddParameter("@Districts_Mem", data.Districts_Mem);
            cls.AddParameter("@Id_Province_Mem", data.Id_Province_Mem);
            cls.AddParameter("@ID_Domain_Mem", data.ID_Domain_Mem);
            cls.AddParameter("@Id_National_Mem", data.Id_National_Mem);
            cls.AddParameter("@Img_Mem", data.Img_Mem);
            cls.AddParameter("@MaCha", data.MaCha);
            cls.ExecuteNonQuery("sp_TMMember_Insert");
            return true;
        }
        public bool UpdateTMMember(clsTMMemberProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Member_ID", data.Member_ID);
            cls.AddParameter("@Member_Alias", data.Member_Alias);
            cls.AddParameter("@FullNameMem", data.FullNameMem);
            cls.AddParameter("@FullName_E", data.FullName_E);
            cls.AddParameter("@FullName_C", data.FullName_C);
            cls.AddParameter("@Alias_Mem", data.Alias_Mem);
            cls.AddParameter("@Brith_Mem", data.Brith_Mem);
            cls.AddParameter("@Sex_Mem", data.Sex_Mem);
            cls.AddParameter("@Address_Mem", data.Address_Mem);
            cls.AddParameter("@Household_Mem", data.Household_Mem);
            cls.AddParameter("@PlaceOFBirth_Mem", data.PlaceOFBirth_Mem);
            cls.AddParameter("@Origin_Mem", data.Origin_Mem);
            cls.AddParameter("@ID_Religion_Mem", data.ID_Religion_Mem);
            cls.AddParameter("@ID_Ethnicity_Mem", data.ID_Ethnicity_Mem);
            cls.AddParameter("@PhoneNumber_Mem", data.PhoneNumber_Mem);
            cls.AddParameter("@Email_Mem", data.Email_Mem);
            cls.AddParameter("@Number_CMT_Mem", data.Number_CMT_Mem);
            cls.AddParameter("@Number_Car_Mem", data.Number_Car_Mem);
            cls.AddParameter("@Note_Mem", data.Note_Mem);
            cls.AddParameter("@Districts_Mem", data.Districts_Mem);
            cls.AddParameter("@Id_Province_Mem", data.Id_Province_Mem);
            cls.AddParameter("@ID_Domain_Mem", data.ID_Domain_Mem);
            cls.AddParameter("@Id_National_Mem", data.Id_National_Mem);
            cls.AddParameter("@Img_Mem", data.Img_Mem);
            cls.AddParameter("@MaCha", data.MaCha);
            cls.ExecuteNonQuery("sp_TMMember_Update");
            return true;
        }
        public bool DeleteTMMember(int id)
        {
            cls.Delete("sp_TMMember_Delete", "@Member_ID", id);
            return true;
        }
        public bool TMMember_Check_Delete_TMPlan_TransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMMember_Check_Delete_TMPlan_TransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMMember_Check_Delete_TMCommandTransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMMember_Check_Delete_TMCommandTransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMMember_Check_Delete_TMDiaryTransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMMember_Check_Delete_TMDiaryTransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMMember_Check_Delete_TMSalesReport(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMMember_Check_Delete_TMSalesReport", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMMember_Check_Contract(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMMember_Check_Contract", "@ID", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMMember_Check_User(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMMember_Check_User", "@ID", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        #endregion

        #region[Search]
        public DataTable Search(string keywords)
        {
            return cls.Search("sp_TMMember_Search", "@KEYWORDS", keywords);
        }
        #endregion
    }
}